package com.aaa.controller;

import com.aaa.entity.Shopping;
import com.aaa.service.ShoppingService;
import com.aaa.util.DefaultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户管理控制器
 */
@RestController
@RequestMapping("/shopping")
public class ShoppingController {
    @Autowired
    private ShoppingService shoppingService;

    @RequestMapping("/listAll")
    public List<Shopping> listAll(){
        List<Shopping> i = shoppingService.list();
        System.out.println(i);
        return i;
    }

    @RequestMapping("/saveOrUpdate")
    public DefaultMsg saveOrUpdate(Shopping shopping){
        DefaultMsg defaultMsg = new DefaultMsg();
        boolean i = shoppingService.saveOrUpdate(shopping);
        if (!i){
            defaultMsg.setSuccess(0);
            defaultMsg.setError("操作失败");
        }
        return defaultMsg;
    }

    @RequestMapping("/delete")
    public boolean insert(Shopping shopping){
        boolean i = shoppingService.removeById(shopping.getId());
        return i;
    }
}
